package com.codeZ.ObserverPattern.example;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体目标实现类
 *
 * @author codeZhang
 * @Date 2024/8/23 10:31
 */
public class ConcreteSubject implements Subject{

    private final List<Observer> observers = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observers.remove(observer);
    }

    @Override
    public void notifyObservers() {
        for (Observer observer : observers) {
            observer.update();
        }
    }
}
